import { Injectable } from '@nestjs/common';
import axios from 'axios';
import * as cheerio from 'cheerio';
import {writeFile} from 'fs';
import xlsx from "node-xlsx";

@Injectable()
export class AppService {


  getHello(): string {
    return 'Hello World!';
  }

  getDomStr() {
    const url = 'http://quotes.money.163.com/f10/lrb_600519.html#01c06';
    const rule = '#scrollTable > div.col_r > table > tbody > tr:nth-child(41)';
    axios.get(url).then((res) => {
      // console.log('res', res);
      const $ = cheerio.load(res.data);
      // console.log($(rule).text());
      const data = $(rule).text();

      const buf = xlsx.build([data]);
      writeFile('./excel.xlsx', buf, res => {
        console.log('writeFile', res);
      });
    }).catch(err => {
      console.log('getDomStr err', err);
    });
  }
}

